package com.explore.demo.controller;


import com.explore.demo.common.ServerResponse;
import com.explore.demo.pojo.Company;
import com.explore.demo.service.CompanyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sun.security.jgss.HttpCaller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gaolainan
 * @since 2021-04-14
 */
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Resource
    private CompanyService companyService;

    @GetMapping
    @ApiOperation("查询全部公司的信息")
    public ServerResponse query(){
        return companyService.queryAll();
    }

    @PostMapping
    @ApiOperation("创建一个公司的信息")
    public ServerResponse addOne(@RequestParam("companyName") String companyName,@RequestParam("companyDesc") String companyDesc, MultipartFile file, HttpServletRequest request){
        return companyService.addCompany(companyName, companyDesc, file, request);
    }

    @DeleteMapping
    @ApiOperation("通过公司的名称 删除公司的相关信息")
    public ServerResponse deleteByName(String companyName){
        return companyService.deleteByCompanyName(companyName);
    }

    @PostMapping("/{companyName}")
    @ApiOperation("通过公司的名称 查询公司的相关信息")
    public ServerResponse queryByName(@PathVariable("companyName") String companyName){
        return companyService.queryByCompanyName(companyName);
    }

    @PutMapping
    @ApiOperation("更新公司的信息")
    public ServerResponse updateInfo(@RequestBody Company company){
        return companyService.updateCompany(company);
    }

    @PostMapping("/upload")
    @ApiOperation("上传公司的logo的接口")
    public ServerResponse uploadCompanyLogo(MultipartFile file){
        return companyService.uploadCompanyLogo(file);
    }

    @PostMapping("/get_recruitment")
    @ApiOperation("根据公司名称或者对应的信息 和 公司旗下的职位信息")
    public ServerResponse getAllRecruitmentByCompanyName(@RequestParam("companyName") String companyName){
        return companyService.getAllRecruitmentByCompanyName(companyName);
    }
}

